/**************************************************************************
	Replication do-file: "Corruption in Customs"
	Cyril Chalendard, Ana Fernandes, Gael Raballand and Bob Rijkers
	
	Created on: 01/07/2022
**************************************************************************/

clear all
set more off, perm
cap log close
cls

* Extra commands: remove the asterisk to install
*net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
*set scheme cleanplots, perm

* ----------------------- DIRECTORIES AND FOLDERS ----------------------- *

* Directories in which data are stored
global main "PUT YOUR DIRECTORY PATH HERE"
cd "$folder"

* Folders
global outputdata = "$main\Output Data"
cap mkdir "$main\Figures"
global figures = "$main\Figures"

* ----------------------------- BEGINS HERE ----------------------------- *

* -------
* Dataset
* -------
use "$outputdata\CFRR.dta", clear // open dataset

* Select sample
keep if sample_int==1 // keep necessary observations
keep if month_del>=-35 & month_del<=11 // keep necessary observations
replace wfr = . if month_del<0 // replace values for pre-delegated randomization period

* Collapse
global vars "sig_c_i significant_random wfr"
collapse (mean) $vars , by(month_del) // collapse by counter

* Unit value
foreach x in $vars {
	replace `x' = `x'*100
}

* Panel dataset
tsset month_del // set panel variable


* --------
* Figure 6
* --------

twoway (connect sig_c_i month_del, lcolor(gs10) lpattern(shortdash) lwidth(medthick) mcolor(gs10) msymbol(o) msize(small)) ///
		(connect significant_random month_del, lcolor(gs8) lpattern(dash) lwidth(medthick) mcolor(gs8) msymbol(s) msize(small)) ///
		(connect wfr month_del if month_del>=0 & month_del<=11, lcolor(gs6) lpattern(longdash) lwidth(medthick) mcolor(gs6) msymbol(X) msize(medsmall)), ///
		xline(0, lpattern(solid) lwidth(thin) lstyle(grid) lcolor(gs2)) ///
		xlabel(-35(5)11, nogrid) ///
		legend(pos(6) ring(10) col(2) order(1 "Significant excess interaction, calibrated" 2 "Random excess interaction, calibrated" 3 "Withdrawn from randomization") size(small)) ///
		ylabel(, angle(0) labsize(small) nogrid) ///
		ytitle("% of declarations", size(small) color(black)) ///
		xtitle("Months since start of delegated randomization", size(small) color(black)) ///		
		name(Figure_6, replace)
graph export "$figures\Figure_6.eps", as(eps) replace
graph export "$figures\Figure_6.pdf", as(pdf) replace


* -------------------------------- ENDS HERE -------------------------------- *